package com.ruoyi.clothing.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ruoyi.clothing.domain.vo.ImproveUser;
import com.ruoyi.clothing.domain.vo.RegisterUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.clothing.mapper.UserMapper;
import com.ruoyi.clothing.domain.User;
import com.ruoyi.clothing.service.IUserService;

/**
 * 用户管理Service业务层处理
 *
 * @author weh
 * @date 2024-01-18
 */
@Service
public class UserServiceImpl implements IUserService
{
    @Autowired
    private UserMapper userMapper;

    /**
     * 查询用户管理
     *
     * @param id 用户管理主键
     * @return 用户管理
     */
    @Override
    public User selectUserById(Integer id)
    {
        return userMapper.selectUserById(id);
    }

    /**
     * 查询用户管理列表
     *
     * @param user 用户管理
     * @return 用户管理
     */
    @Override
    public List<User> selectUserList(User user)
    {
        return userMapper.selectUserList(user);
    }

    /**
     * 新增用户管理
     *
     * @param user 用户管理
     * @return 结果
     */
    @Override
    public int insertUser(User user)
    {
        return userMapper.insertUser(user);
    }

    /**
     * 修改用户管理
     *
     * @param user 用户管理
     * @return 结果
     */
    @Override
    public int updateUser(User user)
    {
        return userMapper.updateUser(user);
    }

    /**
     * 批量删除用户管理
     *
     * @param ids 需要删除的用户管理主键
     * @return 结果
     */
    @Override
    public int deleteUserByIds(Integer[] ids)
    {
        return userMapper.deleteUserByIds(ids);
    }

    /**
     * 删除用户管理信息
     *
     * @param id 用户管理主键
     * @return 结果
     */
    @Override
    public int deleteUserById(Integer id)
    {
        return userMapper.deleteUserById(id);
    }

    /**
     * 根据用户名查询用户信息
     * @param username
     * @return
     */
    @Override
    public User selectUserByUserName(String username) {
        return userMapper.selectUserByUserName(username);
    }

    /**
     * 验证登陆状态
     * @param username
     * @param password
     * @return
     */
    @Override
    public User verifyUser(String username, String password) {
        User user = userMapper.selectUserByUserName(username);

        if (user != null && password.equals(user.getPassword())){
            return user;
        }
        else {
            return null;
        }
    }

    @Override
    public int updatePassWord(Map map) {
        return userMapper.updatePassWord(map);
    }

    @Override
    public User selectUserByTel(String tel) {
        return userMapper.selectUserByTel(tel);
    }

    @Override
    public int register(RegisterUser registerUser) {
        String username = registerUser.getUsername();
        String password = registerUser.getPassword();
        String confirmPassword = registerUser.getConfirmPassword();
        HashMap<String , Object> map = new HashMap<>();
        map.put("username",username);
        map.put("password",password);
        map.put("confirmPassword",confirmPassword);
        userMapper.register(map);
        return 1;
    }

    @Override
    public int improveUser(ImproveUser improveUser) {
        String username = improveUser.getUsername();
        User user = userMapper.selectUserByUserName(username);
        String name = improveUser.getName();
        String headshot = improveUser.getHeadshot();
        String sex = improveUser.getSex();
        String tel = improveUser.getTel();
        HashMap<String, Object> map = new HashMap<>();
        map.put("username",username);
        map.put("name",name);
        userMapper.improveUser(map);
        return 1;
    }

    @Override
    public int improveSex(ImproveUser improveUser) {
        String username = improveUser.getUsername();
        String sex = improveUser.getSex();
        HashMap<String, Object> map = new HashMap<>();
        map.put("username",username);
        map.put("sex",sex);
        userMapper.improveSex(map);
        return 1;
    }

    @Override
    public int improveTel(ImproveUser improveUser) {
        String username = improveUser.getUsername();
        String tel = improveUser.getTel();
        HashMap<String, Object> map = new HashMap<>();
        map.put("username",username);
        map.put("tel",tel);
        userMapper.improveTel(map);
        return 1;
    }
}
